#!/bin/sh
#
## $Id: gdev,v 1.1.1.1 2004/03/08 21:42:12 bigbinc Exp $
##
## Berlin Brown (berlin.brown@gmail.com)
##
## Device creation scripts
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
## A PARTICULAR PURPOSE ARE DISCLAIMED.
##
## See LICENSE.OCTANE for more details
##

CUR_DIR=`pwd`
MNTDIR=${CUR_DIR}/mnt
DEV_DIR=${MNTDIR}/dev

# usage: makedev name [ b c u ]  major minor owner group mode
makedev () {

	echo ">> Creating DEV [ $1 $2 $3 $4 $5 $6 $7 ]"

	mknod $DEV_DIR/$1- $2 $3 $4 &&
	chown $5:$6 $DEV_DIR/$1- &&
	chmod $7 $DEV_DIR/$1- &&
	mv -v $DEV_DIR/$1- $DEV_DIR/$1
		
	
}
# End of the function

# Symlink name target
symlink () {
	echo ">> Symlink $1 -->> $2"
	# The symlinks will probably be broken
	ln -s $2 $DEV_DIR/$1	
} 


if [ $DEV_DIR = "/dev" ] ; then

	echo "=== Major Error ==="
	echo " ErrorBot: We cannot edit the root 'dev' directory"
	echo " 		There must be something wrong with "
	echo "		your current directory...."

	exit 1
fi

echo " /// Device Creation Script ///"
echo " >> Running..."

makedev mem c 1 1 root kmem 660
makedev kmem c 1 2 root kmem 660
makedev null c 1 3 root sys 666
makedev port c 1 4 root kmem 660
makedev zero c 1 5 root sys 666

symlink core /proc/kcore

makedev full c 1 7 root sys 666
makedev tty c 5 0 root tty 666

symlink fd /proc/self/fd

symlink stdin /dev/fd/0
symlink stdout /dev/fd/1
symlink stderr /dev/fd/2

makedev fd0      b 2 0 root floppy 660
makedev fd0H1440 b 2 28 root floppy 660
makedev fd0E2880 b 2 32 root floppy 660
makedev fd0h1440 b 2 40 root floppy 660
makedev fd1      b 2 1 root floppy 660
makedev fd1H1440 b 2 29 root floppy 660
makedev fd1E2880 b 2 33 root floppy 660
makedev fd1h1440 b 2 41 root floppy 660


makedev hda b 3 0 root disk 660
makedev hda1 b 3 1 root disk 660
makedev hda2 b 3 2 root disk 660
makedev hda3 b 3 3 root disk 660
makedev hdb b 3 64 root disk 660
makedev hdb1 b 3 65 root disk 660
makedev hdb2 b 3 66 root disk 660
makedev hdb3 b 3 67 root disk 660

makedev tty0 c 4 0 root tty 622

symlink console /dev/tty0

makedev vcs0 c 7 0 root sys 600
makedev vcsa c 7 128 root sys 600
makedev tty1 c 4 1 root tty 666
makedev vcs1 c 7 1 root sys 600
makedev vcsa1 c 7 129 root sys 600
makedev tty2 c 4 2 root tty 666
makedev vcs2 c 7 2 root sys 600
makedev vcsa2 c 7 130 root sys 600
makedev tty3 c 4 3 root tty 666
makedev vcs3 c 7 3 root sys 600
makedev vcsa3 c 7 131 root sys 600
makedev tty4 c 4 4 root tty 666
makedev vcs4 c 7 4 root sys 600
makedev vcsa4 c 7 132 root sys 600


makedev ttyS0 c 4 64 root tty 666
makedev cua0 c 5 64 root uucp 660
makedev ttyS1 c 4 65 root tty 666
makedev cua1 c 5 65 root uucp 660
makedev ttyS2 c 4 66 root tty 666
makedev cua2 c 5 66 root uucp 660
makedev ttyS3 c 4 67 root tty 666
makedev cua3 c 5 67 root uucp 660

echo "...done /// Device Creation ///"
exit 0
